/*
 * 人人信用管理有限公司版权所有.
 * 
 * @Description:
 * 
 * @author: liyuliang
 * 
 * @date: 20 Apr 2017 10:44:16 am
 * 
 * 注意：本内容仅限于人人信用管理有限公司内部传阅，禁止外泄以及用于其他的商业目的.
 */

package com.rrx360.common.dao;

import java.util.List;

public class HqlQueryEntry extends QueryEntry {

  public HqlQueryEntry(CommonDao commonDao) {
    this.commonDao = commonDao;
  }

  public HqlQueryEntry(Class<?> clazz) {
    this.ql = new StringBuffer("from " + clazz.getName() + " ");
  }

  public HqlQueryEntry(String ql) {
    super(ql, null, null, null);
  }

  public HqlQueryEntry(String ql, String countQl) {
    super(ql, countQl, null, null);
  }

  public HqlQueryEntry(String ql, Long start, Integer fetchSize) {
    super(ql, null, start, fetchSize);
  }

  public HqlQueryEntry(String ql, String countQl, Long start, Integer fetchSize) {
    super(ql, countQl, start, fetchSize);
  }

  @Override
  public List exec(long start, int fetchSize) {
    return getCommonDao().find(ql.toString(), params, start, fetchSize);
  }

  @Override
  public List exec() {
    if (start != null && fetchSize != null) {
      return exec(start, fetchSize);
    }
    return getCommonDao().find(ql.toString(), params);
  }

  public long execUpdate() {
    return getCommonDao().update(ql.toString(), params);
  }

  @Override
  public long execCount() {
    if (countQl == null) {
      convertQlToCountQl();
    }
    return getCommonDao().count(countQl.toString(), params);
  }
}
